﻿using Silk.NET.Input;
using Silk.NET.Maths;
using Silk.NET.Windowing;


namespace Test
{
    internal class Program
    {
        internal static IWindow _Window;
        public static LearnClass CurrentLearnClass;

        static void Main(string[] args)
        {
            CurrentLearnClass = new Learn_03_Abstractions();

            WindowOptions options = WindowOptions.Default with
            {
                Size = new Vector2D<int>(800, 600),
                Title = CurrentLearnClass.Name,
            };

            _Window = Window.Create(options);

            _Window.Load += OnLoad;
            _Window.Update += OnUpdate;
            _Window.Render += OnRender;

            _Window.Run();
        }

        private static void OnLoad() 
        {
            IInputContext input = _Window.CreateInput();
            for (int i = 0; i < input.Keyboards.Count; i++)
                input.Keyboards[i].KeyDown += KeyDown;

            CurrentLearnClass?.OnLoad();
        }

        private static void OnUpdate(double deltaTime) 
        {
            CurrentLearnClass?.OnUpdate(deltaTime);

        }

        private static void OnRender(double deltaTime) 
        {
            CurrentLearnClass?.OnRender(deltaTime);

        }

        private static void KeyDown(IKeyboard keyboard, Key key, int keyCode) 
        {
            Console.WriteLine("Input: " + keyboard.Name + " : " + key + " " + keyCode);

            CurrentLearnClass?.OnKeyDown(keyboard,key,keyCode);


            //if (key == Key.Escape)
            //    _Window.Close();
        }

    }
}
